<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数值计算器</title>
</head>
<body>
  <script>
    const numbers = [
      2.481,2.484,2.462,2.466,2.458,
      2.467,2.453,2.457,2.457,2.462,
      2.496,2.500,2.470,2.462,2.459,
      2.473,2.466,2.469,2.483,2.480,
      2.509,2.483,2.466,2.472,2.490,
    ]

    //计算最大值和最小值
    let max = numbers[0] 
    let min = numbers[0]
    for (let i = 0; i < numbers.length; i++) {
      if (numbers[i] > max){
        max = numbers[i]
      }
      if (numbers[i] < min){
        min = numbers[i]
      }
    }


    //计算平均值
    let sum = 0
    for (let i = 0; i<numbers.length; i++) {
      sum += numbers[i]
    }
    const average = sum / numbers.length


    //计算最大偏差（绝对偏差 = |单个值 - 平均值|）
    let maxDeviation = 0 // 初始最大偏差为0
      for (let num of numbers) {
        const deviation = Math.abs(num - average) // 计算当前值的绝对偏差
      if (deviation > maxDeviation) { // 若当前偏差更大，更新最大偏差
        maxDeviation = deviation
      }
  }

    // 筛选小于和大于平均值的数
    const xyAverage = []
    const dyAverage = []
    for (let num of numbers) {
      if (num < average) {
        xyAverage.push(num)
      } else if (num > average) {
        dyAverage.push(num)
      }
    } 

    //输出结果
    console.log("最大值：",max.toFixed(3))
    console.log("最小值：",min.toFixed(3))
    console.log("平均值：",average.toFixed(3))
    console.log("单个值与平均值的最大偏差：",maxDeviation.toFixed(3))
    console.log("小于平均值的数：",xyaverage.map(num =>num.toFixed(3)).join(""))
    console.log("大于平均值的数：",dyaverage.map(num =>num.toFixed(3)).join(""))
  </script>
</body>
</html>